package level.model;

import java.util.ArrayList;
import java.util.Set;
import java.util.TreeMap;

public class Selection
{
	public Selection()
	{
		selections = new TreeMap<Integer, ArrayList<Addable>>();
	}

	public boolean isEmpty()
	{
		return selections.isEmpty();
	}

	public Set<Integer> keySet()
	{
		return selections.keySet();
	}

	public ArrayList<Addable> get(Integer i)
	{
		return selections.get(i);
	}

	public void add(Selection selection)
	{
		for (Integer i : selection.keySet())
		{
			this.add(i, selection.get(i));
		}
	}

	public void add(Integer i, ArrayList<Addable> toAdd)
	{
		if (selections.containsKey(i))
		{
			ArrayList<Addable> addTo = selections.get(i);
			for (Addable add1 : toAdd)
			{
				boolean duplicate = false;
				for (Addable add2 : addTo)
				{
					if (add2.equals(add1))
						duplicate = true;
				}
				if (duplicate == false)
				{
					addTo.add(add1.cloneAddable());
				}
			}
		}
		else
			selections.put(i, toAdd);
	}

	public void clear()
	{
		selections.clear();
	}
	
	private TreeMap<Integer, ArrayList<Addable>> selections;
}
